#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 105;

int n, s;
struct Node {
  int v, t;
};
vector<Node> a[N];
int calc(int p1, int p2) {
  int cnt = 0;
  const vector<Node>& b1 = a[p1];
  const vector<Node>& b2 = a[p2];
  int pre = 1, s1 = b1[0].v, s2 = b2[0].v;
  int res = s1 > s2 ? 1 : 0;
  int n1 = b1.size(), n2 = b2.size();
  int i = 0, j = 0;
  while (i < n1 && j < n2) {
    int t1 = b1[i].t, t2 = b2[j].t;
    int now = min(t1, t2);
    s1 += (now - pre) * b1[i].v;
    s2 += (now - pre) * b2[j].v;
    if (s1 != s2) {
      if ((s1 > s2) != res) cnt++, res = s1 > s2 ? 1 : 0;
    }
    if (now == b1[i].t) i++;
    if (now == b2[j].t) j++;
    pre = now;
  }
  return cnt;
}
void solve() {
  cin >> n >> s;
  rep(i, 1, n) {
    int k;
    cin >> k;
    int t0 = 0;
    rep(j, 1, k) {
      int v, t;
      cin >> v >> t;
      a[i].push_back({v, t + t0});
      t0 += t;
    }
  }
  ll ans = 0;
  rep(i, 1, n) rep(j, 1, i - 1) ans += calc(i, j);
  cout << ans;
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}